package vip.xiaonuo.smzq.modular.jsc.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import vip.xiaonuo.smzq.modular.jsc.entity.Kyq;
import vip.xiaonuo.smzq.modular.jsc.mapper.KyqMapper;
import vip.xiaonuo.smzq.modular.jsc.service.IKyqService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * 驾驶舱矿业权统计 服务实现类
 *
 * @author sqq
 * @since 2024-05-13
 */
@Service
public class KyqServiceImpl extends ServiceImpl<KyqMapper, Kyq> implements IKyqService {

    @Resource
    private KyqMapper kyqMapper;

    @Override
    public Page<Kyq> page(Kyq kyq) {
        QueryWrapper<Kyq> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Override
    public void add(List<Kyq> kyqList) {

         for (Kyq kyq1 : kyqList){
             if (kyq1.getXzqhdm() != null&& kyq1.getNd() != null) {
                 kyqMapper.delete(new QueryWrapper<Kyq>().eq("xzqhdm", kyq1.getXzqhdm()).eq("nd", kyq1.getNd()));
             }
         }

            for (Kyq kyq1 : kyqList){
                String uuid = UUID.randomUUID().toString();
                kyq1.setPkid(uuid);
                kyqMapper.insert(kyq1);
            }
        }


    @Override
    public List<Kyq> kyqList(Integer nd, String xzqhdm) {
        QueryWrapper<Kyq> queryWrapper = new QueryWrapper<>();
        if (nd != null ){

            queryWrapper.eq("nd",nd);
        }
        if (xzqhdm != null){
            xzqhdm = xzqhdm.replaceAll("0+$", "");
            queryWrapper  .like("xzqhdm",xzqhdm);
        }

        queryWrapper.orderByAsc("xzqhdm");
        return kyqMapper.selectList(queryWrapper);
    }
}
